home *** CD-ROM | disk | FTP | other *** search
- /* nroff.c - a replacement for the nroff shell script that comes */
- /* with the GNU distribution of groff 1.07 */
- /* Written by Hildo Biersma on March 6, 1993 */
- /* GNU public license applies - please see the file COPYING for details. */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
-
- /* These aren't defined in <unistd.h>, but should have been... */
- extern int optind, opterr;
- extern char *optarg;
-
- void main(int argc, char *argv[])
- {
- char **arg_vector;
- int arg_counter;
- char option, *ptr;
- size_t len;
-
- if ((arg_vector = malloc((argc + 5) * sizeof(char *))) == NULL)
- {
- fprintf(stderr, "%s: out of memory\n", argv[0]);
- exit(1);
- }
-
- arg_vector[0] = "groff";
- arg_vector[1] = "-Wall";
- arg_vector[2] = "-mtty-char";
- arg_vector[3] = "-Tascii";
- arg_counter = 4;
- while ((option = getopt(argc, argv, "heqs:m:r:n:o:T:i")) != EOF)
- {
- switch(option)
- {
- case 'h':
- arg_vector[arg_counter++] = "-P-h";
- break;
- case 'e':
- case 'q':
- case 's':
- /* Ignore these options */
- break;
- case 'i':
- arg_vector[arg_counter++] = "-i";
- break;
- case 'm':
- case 'r':
- case 'n':
- case 'o':
- /* Pass these arguments on, including their parameters */
- len = strlen(optarg);
- if ((ptr = malloc(len + 3)) == NULL)
- {
- fprintf(stderr, "%s: out of memory\n", argv[0]);
- exit(1);
- }
- arg_vector[arg_counter++] = ptr;
- ptr[0] = '-';
- ptr[1] = option;
- strncpy(ptr + 2, optarg, len);
- ptr[len + 2] = 0x00;
- break;
- case 'T':
- /* Only allow -Tascii and -Tlatin1 */
- if (strcmp(optarg, "ascii") == 0)
- arg_vector[3] = "-Tascii";
- else if (strcmp(optarg, "latin1") == 0)
- arg_vector[3] = "-Tlatin1";
- /* ignore other -T options */
- break;
- default:
- /* This should only get '?', for illegal options */
- break;
- } /* End of switch (options) */
- } /* End of while (options left) */
-
- while (optind < argc)
- arg_vector[arg_counter++] = argv[optind++];
- arg_vector[arg_counter] = NULL;
-
- /* Now execute groff using the argument vector just built */
- execvp("groff", arg_vector);
-
- /* This should never be reached */
- fprintf(stderr, "%s: error in execvp()\n", argv[0]);
- exit(1);
- } /* End of main() */
-